package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.CompanyBaseDAO;
import com.yang.doctorrecruitment.dto.CompanyBase;
import com.yang.doctorrecruitment.utils.NullChange;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Map;

public class CompanyBaseAction extends ActionSupport {
    public CompanyBase companybase;


    public String CompanyBase(){
        String CompanyName= NullChange.NullChange(companybase.getCompanyName());
        String CompanyCorporation=NullChange.NullChange(companybase.getCompanyCorporation());
        String CompanyNature=NullChange.NullChange(companybase.getCompanyNature());
        int CompanyScale= companybase.getCompanyScale();
        int CompanyType=companybase.getCompanyType();
        String CompanyAddress=NullChange.NullChange(companybase.getCompanyAddress());
        String CompanyTelphone= NullChange.NullChange(companybase.getCompanyTelphone());
        String CompanyEmail=NullChange.NullChange(companybase.getCompanyEmail());
        File Companylicense=companybase.getCompanylicense();
        String CompanyIntroduce=NullChange.NullChange(companybase.getCompanyIntroduce());

        //获取到所有的属性保存起来，veryeasy
//        第一步：将信息封装成companybase,
//        第二步：如果照片不为空就上传,上传暂时没做，需要重做！
//        第三步：规定照片的名称

        CompanyBase companyBase=new CompanyBase();
        companyBase.setCompanyName(CompanyName);
        companyBase.setCompanyCorporation(CompanyCorporation);
        companyBase.setCompanyNature(CompanyNature);
        companyBase.setCompanyScale(CompanyScale);
        companyBase.setCompanyType(CompanyType);
        companyBase.setCompanyAddress(CompanyAddress);
        companyBase.setCompanyTelphone(CompanyTelphone);
        companyBase.setCompanyEmail(CompanyEmail);
        companyBase.setCompanyIntroduce(CompanyIntroduce);


        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");
        String photo="license"+UserID;
        boolean res= CompanyBaseDAO.insertCompany(companyBase,UserID,photo);
        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        if(res){
            request.setAttribute("tipMessage",1);
            return SUCCESS;
        }else{
            request.setAttribute("tipMessage",2);
            return ERROR;
        }

    }
    public CompanyBase getCompanybase() {
        return companybase;
    }

    public void setCompanybase(CompanyBase companybase) {
        this.companybase = companybase;
    }
}
